<template>
	<view class="container" :style="{height:h}">
		<view class="nav" :style="{height:nav_h}">
			<view class="navigation">
				<image src="../../static/images/back.png" v-on:click="reback"></image>
			</view>
		</view>
		<view class="nav_lh" :style="{height:nav_lh}"></view>
		<block v-if="status==1">
			<image :style="{height:h}" :src="advs[0]" v-on:click="preview_adv"></image>
		</block>
		<block v-if="status==0">
			<view class="content">{{content}}</view>
			<view class="button" v-on:click="apply">申请推广二维码</view>
		</block>
		<block v-if="status==2">
			<view class="content">已经申请了，请耐心等待。或者直接联系客服加快审核速度</view>
		</block>
	</view>
</template>
<style>
	.container{width:100%;display: flex;flex-direction: column;justify-content: center;align-items: center;background: #FFFFFF;}
	image{width:100%;}
	.nav{width:100%;padding-bottom: 20upx;display: flex;justify-content: flex-start;z-index: 999;
		align-items: flex-end;position: fixed;top:0;left:0;background: #F4F4F4;}
	.navigation{width:95%;padding-left:5%;height: 50upx;font-size: 28upx;color: #333;text-align: center;display: flex;justify-content: flex-start;align-items: center;}
	.navigation image{width:35upx;height: 35upx;}
	.navigation view{font-size: 32upx;color: #333;text-align: center;margin-left:33%;}
	.nav_lh{width:100%;}

	.content{width:96%;font-size: 26upx;line-height: 50upx;text-align: center;}
	.button{width:92%;margin:10upx 4%;height: 80upx;background-image: linear-gradient(#43eac9, #24c3a4);color: #FFFFFF;line-height: 80upx;font-size: 28upx;text-align: center;}
</style>
<script>
	export default {
		data() {
			return {
				w:0,
				h:0,
				nav_h:0,
				status:0,
				content:'',
				advs:[],
				url: getApp().globalData.url,
				img_url:getApp().globalData.static
			}
		},
		onLoad(e) {
			var res      = uni.getSystemInfoSync();
			var width    =  res.windowWidth;
			var height   =  res.windowHeight;
			this.w       = width+"px";
			this.h       = height+"px";
			this.nav_h  = res.statusBarHeight +35+ "px";
			
			this.initialize(e.type);
		},
		onShow(){
			
		},
		methods: {
			initialize:function(type)
			{
				var member_id   = uni.getStorageSync("member_id");
				var that = this;
				uni.request({
					url: this.url+'/wechat_recommend_qrcode', 
					data: {member_id:member_id},
					header: {'Content-Type': 'application/json'},
					success: (res) => {
						console.log(res.data);
						that.advs.push(res.data.url+res.data.result);
						that.status = res.data.member[0].status;
						that.content = res.data.content;
					}
				});
			},
			reback:function()
			{
				uni.navigateBack();
			},
			apply:function()
			{
				var member_id   = uni.getStorageSync("member_id");
				var that = this;
				uni.request({
					url: this.url+'/wechat_apply_qrcode', 
					data: {member_id:member_id},
					header: {'Content-Type': 'application/json'},
					success: (res) => {
						if(res.data.status==1)
						{
							uni.showToast({
								title:"申请成功",
								duration:2000
							})
						}
						if(res.data.status==0)
						{
							uni.showToast({
								title:"已经申请了",
								duration:2000
							})
						}
					}
				});
			},
			preview_adv:function(e)
			{
				uni.previewImage({
					current:this.advs[e.currentTarget.dataset.index],
					urls:this.advs,
					success:(res)=>{
						
					}
				});
			}
		}
	}
</script>